package com.wanda.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wanda.model.JsonModelGeneral;
import com.wanda.model.OrganizationModel;
import com.wanda.model.Wd_UserModel;
import com.wanda.service.OrganizationService;
import com.wanda.util.DateFormat;

@Controller
@RequestMapping(value="/qt/Organization")
public class OrganizationController {

	@Resource
	private OrganizationService organizationService;
	
	
	@RequestMapping(value="/addOrganization.do")
	 public @ResponseBody Map<String,Object> add(OrganizationModel organizationModel, HttpServletRequest request){
		Map<String,Object> map = new HashMap<String,Object>(); 
		Wd_UserModel user= (Wd_UserModel) request.getSession().getAttribute("bean");
		organizationModel.setDelete_user(user.getName());
		organizationModel.setUpdate_user(user.getName());
		organizationModel.setUpdate_time(DateFormat.getNowDate());
		organizationModel.setDelete_time(DateFormat.getNowDate());
		
		organizationService.addOrganization(organizationModel);
		System.out.println("添加成功"); 
    	map.put("msg","成功");
		return map;
	}
	
	@RequestMapping(value="/deleteOrganization.do")
	 public @ResponseBody Map<String,Object> update(String organization_id , HttpServletRequest request){
		Map<String,Object> map = new HashMap<String,Object>(); 
		
		
		organizationService.deleteOrganization(organization_id);
		System.out.println("删除成功"); 
   	map.put("msg","成功");
		return map;
	}
	
	@RequestMapping(value="/selectAll.do")
    public @ResponseBody JsonModelGeneral select(){
		JsonModelGeneral json = new JsonModelGeneral();
		json.setRows(organizationService.selectOrganizationall());
		return json;
	}
	
	@RequestMapping(value="/selectById.do")
    public @ResponseBody JsonModelGeneral selectbyid(String organization_id){
		JsonModelGeneral json = new JsonModelGeneral();
		System.err.println(organizationService.selectOrganizationById(organization_id).get(0).getDelete_time());
		System.err.println(organizationService.selectOrganizationById(organization_id).get(0).getOrganization_name());
		System.err.println(organizationService.selectOrganizationById(organization_id).get(0).getOrganization_id());
		
		json.setRows(organizationService.selectOrganizationById(organization_id));
		return json;
	}
	
	@RequestMapping(value="/updateOrganization.do")
    public @ResponseBody Map<String,Object> updateOrganization(OrganizationModel organizationModel, HttpServletRequest request){
		Map<String,Object> map = new HashMap<String,Object>(); 
		Wd_UserModel user= (Wd_UserModel) request.getSession().getAttribute("bean");
		organizationModel.setDelete_user(user.getName());
		organizationModel.setUpdate_user(user.getName());
		organizationModel.setUpdate_time(DateFormat.getNowDate());
		organizationModel.setDelete_time(DateFormat.getNowDate());
		
		organizationService.updateOrganization(organizationModel);
		map.put("msg","成功");
		return map;
	}
	
	
}
